<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>支出-添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script type="text/javascript" src="./js/ie/html5.min.js"></script>
    <script type="text/javascript" src="./js/ie/respond.min.js"></script>
    <![endif]--></head>
<body>

<form class="layui-form" action="" lay-filter="example">
    <input type="hidden" value="B" name="jurisdiction" id="jurisdiction">
    <input type="hidden" value="1" name="valid" id="valid">

    <div class="layui-form-item">
        <label for="nameLogin" class="layui-form-label">
            <span class="x-red">*</span>账号</label>
        <div class="layui-input-inline">
            <input type="text" placeholder="请输入用户名" id="nameLogin" name="nameLogin" required="" lay-verify="nameLogin" autocomplete="off" class="layui-input">
        </div>
        <!-- 对号 -->
        <div class="layui-form-mid">
            <i class="layui-icon" id="ri" style="color: green;font-weight: bolder;" hidden>ok</i>
        </div>
        <!-- 错号 -->
        <div class="layui-form-mid">
            <i class="layui-icon" id="wr" style="color: red; font-weight: bolder;" hidden>false</i>
        </div>
    </div>
    <div class="layui-form-item">
        <label for="password" class="layui-form-label">
            <span class="x-red">*</span>密码</label>
        <div class="layui-input-inline">
            <input type="text" placeholder="请输入密码" id="password" name="password" required="" lay-verify="pass" autocomplete="off"
                   class="layui-input"></div>
    </div>
    <div class="layui-form-item">
        <label for="nameUser" class="layui-form-label">
            <span class="x-red">*</span>用户姓名</label>
        <div class="layui-input-inline">
            <input type="text" id="nameUser" name="nameUser" required="" lay-verify="required" autocomplete="off"
                   class="layui-input"></div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" disabled="disabled" id="submit1" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        $('#nameLogin').blur(function() {
            var user = $(this).val();
            $.ajax({
                url:'/adminUserNameLoginEqualTo',
                type:'post',
                dataType:'text',
                data:{nameLogin:user},
                //验证用户名是否可用
                success:function(data){
                    if (data == 0) {
                        $('#ri').removeAttr('hidden');
                        $('#wr').attr('hidden','hidden');
                        $('#submit1').removeAttr("disabled");
                    } else {
                        $('#wr').removeAttr('hidden');
                        $('#ri').attr('hidden','hidden');
                        $('#submit1').attr("disabled","disabled");
                        layer.msg('当前用户名已被占用! ')
                    }
                }
            })
        });
        form.verify({
            nameLogin: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '用户名不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '用户名不能全为数字';
                }
            },
            pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });
        //监听提交
        form.on('submit(demo1)', function (data) {
            var valid = 1;
            var nameLogin = document.getElementById("nameLogin").value;
            var password = document.getElementById("password").value;
            var nameUser = document.getElementById("nameUser").value;
            var jurisdiction = "B";
            $.ajax({
                type: "post",
                url: "/adminAddUser",
                data: {
                    valid: valid,
                    nameLogin: nameLogin,
                    password: password,
                    nameUser: nameUser,
                    jurisdiction: jurisdiction
                },
                dataType: 'json',
                success: function (data) {
                },
                error: function (data) {
                    console.log("error");
                    console.log(data)
                }
            });
            layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                },
                function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
            return false;
        });
    });
</script>

</body>


</html>